﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HttpService;
using System.Net;

namespace MiniHttpServer
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpServer http_server = new HttpServer(IPAddress.Any, 8080);
            while (true)
            {
                var task = http_server.PopTask();
                while (task != null)
                {

                    Console.WriteLine("userip:" + task.Request.UserHost + " url:" + task.Request.RequestUrl);
                    // TODO anything about http
                    switch (task.Request.Paths[0])
                    {
                        case "example":// http://localhost:8080/example
                            task.Response.AddHeader("Content-Type", "text/html; charset=utf-8");
                            task.Response.Write("<html><head><title>minihttp</title></head><body>mini http server example</body></html>");
                            break;
                    }
                    task.Response.End();
                    task = http_server.PopTask();
                }
            }
        }
    }
}
